﻿<cfscript>
/** 
* DataBase Frameworks - Sequence
* 
* @hint "DataBase Frameworks - Sequence - ExamTask" 
*/ 

component 
	displayname="public.service.db.senate.sequence.ExamTask" 
	output=false 
	accessors=true 
	{
		
	property type="string" name="TermID" hint="学期代码";
	property type="string" name="ExamType" hint="考试类别";
	property type="string" name="ExamIndex" hint="考序号";

	/**
	* @hint "初始化对象"
	*/
	public function init() output=false {
		return this;
	}
	
	/**
	* @hint "生成考序号"
	* 
	* @Term "学期"
	* @ExamType "考试类别"
	*/
	public string function getExamIDX() output=false {
		
		/* 
			考序号规则 6位代码
		*/
		var nextID = numberFormat(1, "0_____");
			
		var sql = "	SELECT exidx FROM t_examtask 
					  WHERE
						  term_id = :termId 
						  AND
						  exam_type = :examType 
					  ORDER BY
						  exidx DESC ";
						  
		queryObj = new Query( datasource=application.dnsMaster, maxRows=1 );
		queryObj.addParam( name="termId", value=getTermID(), cfsqltype="cf_sql_char" );
		queryObj.addParam( name="examType", value=getExamType(), cfsqltype="cf_sql_char" );	
		var rs_check = queryObj.execute( sql=sql ).getResult();
	
		if (rs_check.recordCount) {
			/* 创建一个追加id */
			nextID = numberFormat((rs_check.exidx + 1), "0_____");
		}

		return nextID;
	}
	/**
	* @hint "自定义主键规则"
	* 
	* @Term "学期"
	* @ExamType "考试类别"
	* @ExamIndex "考序号"
	*/	
	public string function getID() output=false {
		
		var nextID = getTermID() & getExamType() & getExamIndex();

		/* 
			主键生成规则 
			
			考试任务号10位 3位学期代码 1位考试类别代码[H-半期 F-期末 S-分散考试] 6位考序号

			Unique: TERM_ID, EXAMTYPE, EXAMIDX
		*/
		return nextID;
	}

}

</cfscript>